<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${entityName}Mapper">

	<sql id="selectField">
	<#list dataList as var>	
		${var.columnName} as "${var.newColumn}"<#if var_has_next>,</#if>
	</#list>
	</sql>

	<!-- 新增数据 -->
	<insert id="save" parameterType="pd">
		INSERT INTO 
			${tableName}(
    		<#list dataList as var>	
		    	${var.columnName}<#if var_has_next>,</#if>
		    </#list>
			)VALUES(
	    	<#list dataList as var>	
		    	 ${r"#{"}${var.newColumn}${r"}"}<#if var_has_next>,</#if>
		    </#list>
        	)
	</insert>
	
	<!-- 批量新增数据 -->
	<insert id="saveBatch" parameterType="java.util.List">
		INSERT INTO 
			${tableName}(
		    <#list dataList as var>	
		    	${var.columnName}<#if var_has_next>,</#if>
		    </#list>
			)VALUES
		<foreach collection="list" item="item" index="index" separator="," >
                (
		    	<#list dataList as var>	
		    	 ${r"#{item."}${var.newColumn}${r"}"}<#if var_has_next>,</#if>
		    	</#list>
                )
    	</foreach >
	</insert>
	
<#list dataList as var>
	
	<!-- 根据${var.newColumn}获取${entityName}  -->
	<select id="getListBy${var.newColumnBigger}" parameterType="Long" resultType="pd">
		SELECT 
			<include refid="selectField" />
		FROM 
			${tableName}
		WHERE
			${var.columnName} = ${r"#{"}${var.newColumn}${r"}"}
	</select>		
</#list>	
<#list dataList as var>	

	<!-- 根据${var.newColumn}删除${entityName} -->
	<delete id="deleteBy${var.newColumnBigger}" parameterType="Long">
		DELETE FROM 
			${tableName}
		WHERE
			${var.columnName} = ${r"#{"}${var.newColumn}${r"}"}
	</delete>		
</#list>	
	
	
</mapper>